import sys
from os.path import join, dirname

from loguru import logger

from config import settings

log_config = {
    "handlers": [
        {
            "sink": sys.stdout,
            "level": settings.log.std_level,
        },
        {
            "sink": join(dirname(__file__), 'log_files', '{time:YYYY-MM-DD}.log'),  # log文件的路径
            "format": "{time:YYYY-MM-DD HH:mm:ss} | {level} | {file}:{line} | {message}",
            "enqueue": True,
            "rotation": '00:00',  # 每天 0 点创建一个文件
            "level": settings.log.file_level,
            "encoding": "utf-8",
        },
    ]
}
logger.configure(**log_config)
